package main

import (
	"fmt"
)

type Node struct {
	Data  int
	Left  *Node
	Right *Node
}

func main() {
	tree := &Node{Data: 0}
	tree1 := &Node{Data: 1}
	tree22 := &Node{Data: 2}
	tree3 := &Node{Data: 3}
	tree4 := &Node{Data: 4}
	tree5 := &Node{Data: 5}
	tree1.Left = tree3
	tree1.Right = tree4
	tree22.Right = tree5
	tree.Left = tree1
	tree.Right = tree22
	//PreTravesal(tree)
	//MidTravesal(tree)
	PostTravesal(tree)
}

func PreTravesal(tree *Node) {
	if tree == nil {
		return
	}
	fmt.Println(tree.Data)
	PreTravesal(tree.Left)
	PreTravesal(tree.Right)
}

func MidTravesal(tree *Node) {
	if tree == nil {
		return
	}
	MidTravesal(tree.Left)
	fmt.Println(tree.Data)
	MidTravesal(tree.Right)
}

func PostTravesal(tree *Node) {
	if tree == nil {
		return
	}
	PostTravesal(tree.Left)
	PostTravesal(tree.Right)
	fmt.Println(tree.Data)
}
